﻿using System;
using ChatServerApp.Tools;

namespace ChatServerApp.Classes
{
    class ClientObject
    {
        int id;
        string nickName,
               pw,
               ip;
        int serverPort;
        string[] contacts;
        bool isOnline;

        public ClientObject(int Id, string Nick, string Pw, string Ip, int port, string Contacts, bool IsOnline)
        {
            this.id = Id;
            this.nickName = Nick;
            this.pw = Pw;
            this.ip = Ip;
            this.serverPort = port;
            this.contacts = Contacts.ToAsciiString("|");
            this.isOnline = IsOnline;
        }

        public int Id
        {
            get { return id; }
            set { id = value; }
        }
        public string Pw
        {
            get { return pw; }
            set { pw = value; }
        }
        public string NickName
        {
            get { return nickName; }
            set { nickName = value; }
        }
        public string Ip
        {
            get { return ip; }
            set { ip = value; }
        }
        public string[] Contacts
        {
            get { return contacts; }
            set { contacts = value; }
        }
        public bool IsOnline
        {
            get { return isOnline; }
            set { isOnline = value; }
        }
        public string ContactsString
        {
            get { 
                string ret = "";
                foreach (string element in contacts)
                    ret += element + "|";

                ret = ret.Substring(0, ret.LastIndexOf("|"));

                return ret; }
        }
        public void Update(String IpA, int port, bool status)
        {
            this.ip = IpA;
            this.isOnline = status;
            this.serverPort = port;
        }
        public int ServerPort
        {
            get { return serverPort; }
        }
    }
}
